<template>
  <div class="remindInput clearfix">
    <div class="left">
      <div class="detail_main">
        <div class="detail_top">
          <h2>当前回访信息</h2>
        </div>
        <FormPanel ref="currentVisit" :list="formList" :cols="2" :isSubmitBtn="false" :collapse="false" :labelWidth="120" @formChange="changeHandle" />
      </div>
      <!-- <div class="detail_main">
        <div class="detail_top">
          <h2>上次回访信息</h2>
        </div>
        <FormPanel ref="lastVisit" :list="formList4" :cols="2" :isSubmitBtn="false" :collapse="false" :labelWidth="120" @formChange="changeHandle" />
      </div>-->
    </div>

    <div class="right">
      <div class="detail_main">
        <div class="detail_top">
          <h2>提醒信息</h2>
        </div>
        <div class="detail_containter">
          <FormPanel ref="ownerVisit" :list="formList2" :isSubmitBtn="false" :collapse="false" :labelWidth="120" @formChange="changeHandle2" />
          <!-- <ButtonArea :style="{ paddingLeft: '0px', float: 'right' }">
            <el-button type="primary" icon="el-icon-printer" @click="monitoringBtnFun()">监控信息</el-button>
            <el-button type="primary" @click="showDia(1)">投诉历史</el-button>
            <el-button type="primary" @click="showDia(2)">维修历史</el-button>
            <el-button type="primary" @click="openRemindHistory()">提醒历史</el-button>
            <el-button type="primary" @click="showDia(3)">维修建议</el-button>
          </ButtonArea>-->
          <div style="clear:both;">
            <ToggleTable ref="ToggleTable" :rData="remindData"></ToggleTable>
            <!-- <ToggleText v-if="type == 2" ref="toggleText" :data="this.remindData" :remindSourcePath="this.remindSource"></ToggleText> -->
          </div>
          <div
            :style="{
              position: 'absolute',
              left: 0,
              bottom: 0,
              right: 0,
              zIndex: 9999,
              borderTop: '1px solid #e9e9e9',
              padding: '10px 20px',
              background: '#fff',
              textAlign: 'right'
            }"
          >
            <el-button type="primary" @click="saveMsg">{{ isTrace === 80581003 || isTrace === 80581004 ? '确定' : '保存' }}</el-button>
            <el-button type="primary" @click="exhale('0')">智能外呼</el-button>
            <el-button type="primary" @click="exhale('00')">加0外呼</el-button>
            <el-button @click="closeDialog">取 消</el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 监控 -->
    <Drawer :visible.sync="ismonitoring" title="监控车辆提醒" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <MonitoringModal :isAutoAtion="isMonitoringAutoAtion" :queryParams="monitoringQueryParams" @confirm="monitoringConfirm" @cancel="ismonitoring = false" />
    </Drawer>

    <!-- 投诉历史 -->
    <Drawer :visible.sync="showComplaintHistory" title="投诉历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <complaintHistory ref="complaintHistory" :vin="chooseVin" @close="cancle(1)"></complaintHistory>
    </Drawer>

    <!-- 维修历史 -->
    <Drawer :visible.sync="showRepairHistory" title="维修历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <repairHistory ref="repairHistory" :getdata="repairHistoryData" @close="cancle(2)"></repairHistory>
    </Drawer>

    <!-- 提醒历史 -->
    <Drawer :visible.sync="showRemindHistory" title="提醒历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <RemindHistory :vin="chooseVin" :ownerNo="chooseOwnerNo" :remindSource="2" @close="closeRemindHistory" />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9999,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="closeRemindHistory">返 回</el-button>
      </div>
    </Drawer>

    <!-- 维修建议 -->
    <Drawer :visible.sync="showRepairSuggest" title="维修建议" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <!-- <RepairImport ref="RepairImport" :vin="chooseVin" @cancel="cancle(3)" /> -->
    </Drawer>

    <!-- 预约安排 -->
    <Drawer :visible.sync="showReservation" title="预约安排" width="1350" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Precontract ref="Precontract" :Vin="chooseVin" :License="chooseLicense" @close="cancle(4)" />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9999,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="cancle(3)">返 回</el-button>
      </div>
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import ToggleTable from '@/pages/customerRepair/afterSaleVisit/resultEntry/ctiToggleTable';
import ToggleText from '@/pages/customerRepair/customerCare/maintenanceRemind/toggleText';
import { queryRepairBusiness } from '@/api/repair/repairReception/repairBusinessManger';
import { retriveByControl, retriveByControlright, queryActivityValid, searchMobile } from '@/api/repair/repairReception/customer/monitoring.js';
import { addRemind, addQuestion, getLastInfo } from '@/api/customerRepair/customerCare/maintenanceRemind';
// import { getfindAllRepairType } from '@/api/repair/repairReception/customer/history';
import RemindHistory from '@/pages/customerRepair/customerCare/vehicleRemind/components/remindHistory.vue';
import MonitoringModal from '@/pages/customerRepair/customerCare/maintenanceRemind/monitoring/Modal.vue';
import complaintHistory from '@/pages/repair/business/customer/combination/complaint';
import repairHistory from '@/pages/repair/business/customer/Repairhistory/historypop.vue';
// import RepairImport from '@/pages/repair/repairReception/customer/repairImport/Modal.vue';
import Precontract from '@/pages/repair/repairReception/precontractArrange';
import { getModel } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';
export default {
  name: 'remindInputs',
  components: {
    ToggleTable,
    ToggleText,
    RemindHistory,
    MonitoringModal,
    complaintHistory,
    repairHistory,
    // RepairImport,
    Precontract
  },
  mixins: [dictionary],

  props: ['remindData', 'buttonType', 'remindSource', 'phone'],
  data() {
    return {
      type: this.buttonType || 2,
      ismonitoring: false, // 监控
      isMonitoringAutoAtion: false,
      monitoringQueryParams: {},
      // 提示信息
      tiShiInfo: [],
      // 提示信息 监控表格
      dataSource: [],
      dataSource3: [], //  服务活动
      formList: this.createFormList(),
      formList1: this.createdFrom1(),
      formList2: this.createdFrom2(),
      // formList3: this.createdFrom3(),//产品原有就被注释
      // formList4: this.createFormList4(),
      fetchApi2: queryRepairBusiness,
      fetchParams2: { xhrAbort: true },
      columns1: this.createdTable1(),
      columns2: this.createdTable2(),
      columns3: this.createdTable3(),
      dataList2: [],
      showRemindHistory: false,
      isTrace: null,
      chooseVin: null, // 选中的vin
      chooseLicense: null, // 选中的license
      chooseOwnerNo: null, // 选中的数据的ownerNo
      repairHistoryData: {}, // 维修历史数据
      showRepairHistory: false, // 维修历史
      showRepairSuggest: false, // 建议维修
      showComplaintHistory: false, // 投诉历史
      showReservation: false, // 预约安排
      remindSourcePath: null, // 数据来源
      isMustFlag: true,
      flag: true,
      resData: [],
      /* 呼叫中心所需字段----begin */
      afterVal: '',
      HFDH: '',
      ctiUrl: null,
      callId: null
      /* 呼叫中心所需字段 ----end*/
    };
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.remindSourcePath = this.remindSource;
    });
    // this.setDefValue();
    this.typeSelect();
    this.queryEmpolyeeInfo();
    this.getMonitoryTable();
    this.getRepairHistoryTable();
    this.queryActivityValid();
    this.initForm2();
    this.getLastInfo();
    this.isTrace = this.remindData.TRACE_STATUS;
    this.after();
    // this.queryModel();
    // addQuestionnaireType();
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '回访单号',
          fieldName: 'hfdh',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '满意度打分',
          fieldName: 'myddf',
          initialValue: 0,
          rules: [{ required: true, message: '请填写分数', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '回访状态',
          fieldName: 'returnVisitStatus',
          initialValue: '',
          itemList: this.createDictList('1592'),
          rules: [{ required: true, message: '请选择回访状态', trigger: 'change' }]
          // change: val => this.selectChange2(val)
        },
        {
          type: 'CHECKBOX',
          label: '免打扰',
          fieldName: 'sfmdr',
          // initialValue: '10041001',
          options: { trueValue: 10041001, falseValue: 10041002 }
          // rules: [{ required: true, message: '请选择是否免打扰', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '回访状态原因',
          fieldName: 'hfztyy',
          initialValue: '',
          itemList: this.createDictList('8084')
          // rules: [{ required: true, message: '请选择回访状态原因', trigger: 'change' }],
          // change: val => this.selectChange2(val)
        },
        {
          type: 'SELECT',
          label: '回访结果',
          fieldName: 'shfjg',
          initialValue: '',
          itemList: this.createDictList('1075'),
          rules: [{ required: true, message: '请选择回访结果', trigger: 'change' }]
          // change: val => this.selectChange2(val)
        },
        {
          type: 'CHECKBOX',
          label: '需要回访标识',
          fieldName: 'xzhf',
          // initialValue: '10041001',
          options: { trueValue: 10041001, falseValue: 10041002 },
          change: val => this.selectChangehf(val)
        },
        {
          type: 'DATE',
          label: '下次回访日期',
          fieldName: 'nextVisitDate',
          initialValue: '',
          disabled: true,
          rules: []
        },
        {
          type: 'TEXT_AREA',
          label: '其他建议',
          fieldName: 'qtjy',
          selfCols: 1.5,
          rows: 2
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'bz',
          selfCols: 1.5,
          rows: 2,
          maxlength: 100
        },

        {
          type: 'SELECT',
          label: '不满意原因',
          fieldName: 'bmyyyfl',
          initialValue: '',
          itemList: this.createDictList('8201')
          // disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '不满意原因描述',
          fieldName: 'bmyyymx',
          // selfCols: 1.5,
          // rows: 4,
          maxlength: 100
          // disabled:
        },
        {
          type: 'SELECT',
          label: '不满意原因2',
          fieldName: 'bmyyyfl2',
          initialValue: '',
          itemList: this.createDictList('8201')
          // disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '不满意原因描述2',
          fieldName: 'bmyyymx2',
          // selfCols: 1.5,
          // rows: 4,
          maxlength: 100
          // disabled: true
        },
        {
          type: 'SELECT',
          label: '不满意原因3',
          fieldName: 'bmyyyfl3',
          initialValue: '',
          itemList: this.createDictList('8201')
          // disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '不满意原因描述3',
          fieldName: 'bmyyymx3',
          // selfCols: 1.5,
          // rows: 4,
          maxlength: 100
          // disabled: true
        },
        {
          type: 'SELECT',
          label: '不满意原因4',
          fieldName: 'bmyyyfl4',
          initialValue: '',
          itemList: this.createDictList('8201')
          // disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '不满意原因描述4',
          fieldName: 'bmyyymx4',
          // selfCols: 1.5,
          // rows: 4,
          maxlength: 100
          // disabled: true
        },
        {
          type: 'SELECT',
          label: '不满意原因5',
          fieldName: 'bmyyyfl5',
          initialValue: '',
          itemList: this.createDictList('8201')
          // disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '不满意原因描述5',
          fieldName: 'bmyyymx5',
          // selfCols: 1.5,
          // rows: 4,
          maxlength: 100
          // disabled: true
        }
      ];
    },
    createdFrom1() {
      return [
        {
          type: 'TEXT_AREA',
          label: '提醒内容',
          fieldName: 'DEALER_CODE',
          initialValue: ''
        }
      ];
    },
    // createFormList4() {
    //   return [
    //     {
    //       type: 'INPUT',
    //       label: '回访单号',
    //       fieldName: 'hfdh',
    //       // initialValue: '',
    //       disabled:true
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '满意度打分',
    //       fieldName: 'myddf',
    //       // initialValue: '',
    //       disabled:true
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '回访状态',
    //       fieldName: 'visitResult',
    //       initialValue: '',
    //       disabled:true,
    //       itemList: this.createDictList('1075'),
    //       // change: val => this.selectChange2(val)
    //     },
    //     {
    //       type: 'CHECKBOX',
    //       label: '免打扰',
    //       fieldName: 'sfmdr',
    //       // initialValue: '10041001',
    //       disabled:true,
    //       options: { trueValue: 10041001, falseValue: 10041002 }
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '回访状态原因',
    //       fieldName: 'hfztyy',
    //       initialValue: '',
    //       disabled:true,
    //       itemList: this.createDictList('1075'),
    //       // change: val => this.selectChange2(val)
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '回访结果',
    //       fieldName: 'hfjg',
    //       initialValue: '',
    //       disabled:true,
    //       itemList: this.createDictList('1075'),
    //       // change: val => this.selectChange2(val)
    //     },
    //     {
    //       type: 'CHECKBOX',
    //       label: '需要回访标识',
    //       fieldName: 'xzhf',
    //       // initialValue: '10041001',
    //       disabled:true,
    //       options: { trueValue: 10041001, falseValue: 10041002 }
    //     },
    //     {
    //       type: 'DATE',
    //       label: '下次回访日期',
    //       fieldName: 'myddf',
    //       disabled:true,
    //       initialValue: '',
    //     },
    //     {
    //       type: 'TEXT_AREA',
    //       label: '其他建议',
    //       fieldName: 'qtjy',
    //       disabled:true,
    //       selfCols: 1.5,
    //       rows: 2
    //     },
    //     {
    //       type: 'TEXT_AREA',
    //       label: '备注',
    //       fieldName: 'bz',
    //       disabled:true,
    //       selfCols: 1.5,
    //       rows: 2,
    //       maxlength: 100
    //     },

    //     {
    //       type: 'SELECT',
    //       label: '不满意原因',
    //       fieldName: 'bmyyyfl',
    //       initialValue: '',
    //       itemList: this.createDictList('8201'),
    //       disabled: true
    //     },
    //     {
    //       type: 'TEXT_AREA',
    //       label: '不满意原因描述',
    //       fieldName: 'BMYYYMX',
    //       // selfCols: 1.5,
    //       // rows: 4,
    //       maxlength: 100,
    //       disabled:true
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '不满意原因2',
    //       fieldName: 'bmyyyfl2',
    //       initialValue: '',
    //       itemList: this.createDictList('8201'),
    //       disabled: true
    //     },
    //     {
    //       type: 'TEXT_AREA',
    //       label: '不满意原因描述2',
    //       fieldName: 'bmyyymx2',
    //       // selfCols: 1.5,
    //       // rows: 4,
    //       maxlength: 100,
    //       disabled: true
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '不满意原因3',
    //       fieldName: 'bmyyyf3',
    //       initialValue: '',
    //       itemList: this.createDictList('8201'),
    //       disabled: true
    //     },
    //     {
    //       type: 'TEXT_AREA',
    //       label: '不满意原因描述3',
    //       fieldName: 'bmyyymx3',
    //       // selfCols: 1.5,
    //       // rows: 4,
    //       maxlength: 100,
    //       disabled: true
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '不满意原因4',
    //       fieldName: 'bmyyyf4',
    //       initialValue: '',
    //       itemList: this.createDictList('8201'),
    //       disabled: true
    //     },
    //     {
    //       type: 'TEXT_AREA',
    //       label: '不满意原因描述4',
    //       fieldName: 'bmyyymx4',
    //       // selfCols: 1.5,
    //       // rows: 4,
    //       maxlength: 100,
    //       disabled: true
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '不满意原因5',
    //       fieldName: 'bmyyyf5',
    //       initialValue: '',
    //       itemList: this.createDictList('8201'),
    //       disabled: true
    //     },
    //     {
    //       type: 'TEXT_AREA',
    //       label: '不满意原因描述5',
    //       fieldName: 'bmyyymx5',
    //       // selfCols: 1.5,
    //       // rows: 4,
    //       maxlength: 100,
    //       disabled: true
    //     },
    //   ];
    // },
    monitoringFunBefore() {
      this.monitoringQueryParams = {
        MODEL: this.remindData.model,
        SERIES: this.remindData.series,
        // 活动 出险 预约 新能源 参数
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        BRAND: this.remindData.brand,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        dmsFuncId: '35100010',
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        _: new Date().getTime()
      };
    },

    monitoringAutoFun() {
      this.isMonitoringAutoAtion = true;
      this.monitoringFunBefore();
      this.ismonitoring = true;
    },
    monitoringBtnFun() {
      this.isMonitoringAutoAtion = false;
      this.monitoringFunBefore();
      this.ismonitoring = true;
    },

    monitoringConfirm(obj) {
      this.ismonitoring = false;
    },

    // 显示弹框
    showDia(type) {
      this.chooseVin = this.remindData.vin;
      this.chooseLicense = this.remindData.license;
      this.chooseOwnerNo = this.remindData.owner_no;
      switch (type) {
        case 1:
          // 打开投诉历史
          this.showComplaintHistory = true;
          break;
        case 2:
          // 打开维修历史
          this.repairHistoryData = {
            LICENSE: this.remindData.license,
            VIN: this.remindData.vin,
            ENGINE_NO: this.remindData.engine_no,
            OWNER_NAME: this.remindData.owner_name
          };
          this.showRepairHistory = true;
          break;
        case 3:
          // 打开建议维修
          this.showRepairSuggest = true;
          break;
        case 4:
          // 打开预约安排
          this.showReservation = true;
          break;
      }
    },

    // 取消,关闭弹框
    cancle(type) {
      switch (type) {
        case 1:
          // 关闭投诉历史
          this.showComplaintHistory = false;
          break;
        case 2:
          // 关闭维修历史
          this.showRepairHistory = false;
          break;
        case 3:
          // 关闭建议维修
          this.showRepairSuggest = false;
          break;
        case 4:
          // 关闭预约安排
          this.showReservation = false;
          break;
      }
    },

    async initForm2() {
      let res = await searchMobile(this.phone);
      console.log('查询res', res.data[0]);
      let data = res.data[0];
      let newStr = [];
      for (let [key, val] of Object.entries(data)) {
        let param = {
          fieldName: key,
          value: val
        };
        newStr.push(param);
      }
      this.syncFormListData(newStr);
    },

    // 驼峰转换  RO_NO --> roNo
    camelcase(str) {
      let arr = str.split('_');
      let upper = arr.map((val, index) => {
        let lowStr = val.toLowerCase();
        if (index) {
          lowStr = lowStr.charAt(0).toLocaleUpperCase() + lowStr.slice(1);
        }
        return lowStr;
      });
      return upper.join('');
    },

    // 把返回的数据赋值给表单
    syncFormListData(dataList) {
      const formList = [...this.formList2];
      const formFieldNames = formList.map(x => x.fieldName);
      dataList.forEach(x => {
        if (formFieldNames.includes(x.fieldName)) {
          let target = formList.find(k => k.fieldName == x.fieldName);
          if (!target) return;
          target.initialValue = x.value;
        }
      });

      const formListdh = [...this.formList];
      const formFieldNames1 = formListdh.map(x => x.fieldName);
      dataList.forEach(x => {
        if (formFieldNames1.includes(x.fieldName)) {
          let target = formListdh.find(k => k.fieldName == x.fieldName);
          if (!target) return;
          target.initialValue = x.value;
        }
      });
    },
    createdFrom2() {
      return [
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'khmc',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'cph',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'dph',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主电话',
          fieldName: 'khyddh',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'lxrmc',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系人电话',
          fieldName: 'lxryddh',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'cximc',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'cxingmc',
          initialValue: '',
          disabled: true
        }
      ];
    },

    createdTable1() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '监控信息',
          dataIndex: 'MESSAGE',
          sorter: true,
          filter: true
        }
      ];
    },
    createdTable2() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          filterItems: []
        },
        {
          title: '开单日期',
          dataIndex: 'RO_CREATE_DATE',
          sorter: true,
          filter: true
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true
        },
        {
          title: '材料费',
          dataIndex: 'REPAIR_PART_AMOUNT',
          sorter: true,
          filter: true
        },
        {
          title: '维修总金额',
          dataIndex: 'REPAIR_AMOUNT',
          sorter: true,
          filter: true
        }
      ];
    },
    createdTable3() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{props.row.ACTIVITY_CODE}</span>;
          // }
        },
        {
          title: '活动名称',
          dataIndex: 'ACTIVITY_NAME',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{props.row.ACTIVITY_NAME}</span>;
          // }
        },
        {
          title: '活动类型',
          dataIndex: 'ACTIVITY_TYPE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.ACTIVITY_TYPE, '8080')}</span>;
          }
        },
        {
          title: '开始日期',
          dataIndex: 'startTime',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.startTime}</span>;
          }
        },
        {
          title: '结束日期',
          dataIndex: 'END_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '活动总金额',
          dataIndex: 'ACTIVITY_AMOUNT',
          sorter: true,
          filter: true
        }
      ];
    },
    changeHandle(val) {
      this.resData = Object.assign({}, val);
    },
    changeHandle1(val) {},
    changeHandle2(val) {},
    changeHandle3(val) {},

    async getRepairType(val) {
      let res = await getfindAllRepairType();
      // console.log(res,'res')
      let arr = [];
      res.data.forEach(x => {
        arr.push({ text: x.REPAIR_TYPE_NAME, value: x.REPAIR_TYPE_CODE });
      });
      val.forEach(x => {
        arr.forEach(y => {
          if (x.REPAIR_TYPE_CODE == y.value) {
            // console.log(y);
            x.REPAIR_TYPE_CODE = y.text;
          }
        });
      });
    },

    // 页面管控
    typeSelect() {
      this.formList2.map(x => {
        x.disabled = true;
      });
    },
    // 查询所有车型
    async queryModel() {
      const res = await getModel();
      console.log(res, 'res');
      this.formList2.find(x => x.fieldName === 'model').itemList = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));
      const resUser = await getDealerUser();
      // 服务顾问
      this.formList2.find(x => x.fieldName === 'lastConsultantId').itemList = resUser.data.map(x => ({ value: x.userId, text: x.employeeName }));
    },

    // 查询上次回访信息
    async getLastInfo() {
      const queryParams = {
        oldId: this.remindData.oldId
      };
      const res = await getLastInfo();
      let tableStr = [];
      for (let [key, val] of Object.entries(this.res.data)) {
        let param = {
          fieldName: key,
          value: val
        };
        tableStr.push(param);
      }

      // const formList = [...this.formList4];
      // const formFieldNames = formList.map(x => x.fieldName);
      // tableStr.forEach(x => {
      //   if (formFieldNames.includes(x.fieldName)) {
      //     let target = formList.find(k => k.fieldName == x.fieldName);
      //     if (!target) return;
      //     target.initialValue = x.value;
      //   }
      // });
      // this.formList2.find(x => x.fieldName === 'model').itemList = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));11111
    },

    openRemindHistory(data) {
      this.showRemindHistory = true;
    },

    // 关闭历史提醒
    closeRemindHistory(data) {
      this.showRemindHistory = false;
    },

    // 提醒内容
    async queryEmpolyeeInfo() {
      this.chooseOwnerNo = this.remindData.ownerNo;
      this.chooseVin = this.remindData.vin;

      let obj = {
        vin: this.remindData.vin,
        LICENSE: this.remindData.license
      };
      const res = await retriveByControl(obj);
      // console.log(res,'neirong')
      this.tiShiInfo = res.data;
    },

    // 查询 监控信息
    async getMonitoryTable() {
      const params = {
        sort: 'IS_VALID',
        order: 'asc',
        engineNo: this.remindData.engineNo || '',
        MODEL: this.remindData.modelCode || '',
        SERIES: this.remindData.seriesCode || '',
        RONO: this.remindData.roNo || '',
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        BRAND: this.remindData.brandCode || '',
        MILEAGE: this.remindData.lastMaintainMileage,
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        dmsFuncId: '35100010',
        _: '1567144192282'
      };
      const res = await retriveByControlright(params);
      // console.log('查询监控信息', params, res);
      this.dataSource = res.data;
    },

    // 工单历史
    getRepairHistoryTable() {
      let vin = this.remindData.vin;
      // 增加参数 过滤 2年内单据
      let type = 'twoYear';
      this.fetchParams2 = Object.assign({}, { vin, type }, { xhrAbort: false });
      // console.log(this.dataList2,'shuju')
      // console.log(this.columns2)
    },

    // 服务活动
    async queryActivityValid() {
      const params = {
        sort: 'IS_VALID',
        order: 'asc',
        engineNo: this.remindData.engineNo || '',
        MODEL: this.remindData.modelCode || '',
        SERIES: this.remindData.seriesCode || '',
        RONO: this.remindData.roNo || '',
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        BRAND: this.remindData.brandCode || '',
        MILEAGE: this.remindData.lastMaintainMileage,
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        dmsFuncId: '35100010',
        IS_ACTITY_BOOKING: '10041001',
        _: '1567144192282'
      };
      const res = await queryActivityValid(params);
      // console.log('查询可选活动', params, res);
      this.dataSource3 = res.data;
    },

    // 保存
    async saveMsg() {
      let tabletmpList = this.$refs.ToggleTable.tableList;
      // let formList = this.$refs.ToggleTable.formList;
      // 当问卷类型设置的为必填项时，跟踪状态选择成功结束跟踪或者失败结束跟踪时，需要判断必填项的答案要必填，没有填需要弹出提示信息不能保存，当跟踪状态选择未跟踪或者继续跟踪时，答案选项可以不填。
      // console.log(formList, 'formList');
      tabletmpList.forEach(x => {
        // console.log(x, 'xxxx');
        if (x.isMustFilled === 10041001) {
          if (!x.answer) {
            this.isMustFlag = false;
            return;
          } else {
            this.isMustFlag = true;
          }
        }
      });
      if (this.isMustFlag) {
        // this.resData = null;
        this.$refs.currentVisit.SUBMIT_FORM();
        // let questionnaireId = this.$refs.ToggleTable.questionnaireId;
        // 问卷
        let tableList = this.$refs.ToggleTable.tableList;
        console.log('resData111', this.resData);
        console.log('tableList1111', tableList);
        let visitType = 15721001;

        if (this.remindData.questionnaireType == 80031001) {
          visitType = 15721002;
        } else if (this.remindData.questionnaireType == 80031002) {
          visitType = 15721001;
        } else if (this.remindData.questionnaireType == 80031003) {
          visitType = 15721003;
        }
        // 车辆信息
        let obj = Object.assign({}, this.resData, { list: tableList }, { visitType: visitType }, { callid: this.remindData.callId }, { url: this.ctiUrl });
        this.formList2.forEach(x => {
          if (x.initialValue) {
            let resd = JSON.parse(`{"${x.fieldName}":"${x.initialValue}"}`);
            obj = Object.assign(obj, resd);
          }
        });

        if (!tableList.length) {
          return this.$notify.warning({ title: '提示信息', message: '请先选择问题' });
        }

        const res = await addQuestion(obj);
        if (res.resultCode === 200) {
          this.$notify.success({
            title: '提示信息',
            message: '保存成功！'
          });
          this.$emit('close', false);
        }
      } else {
        this.$message({
          type: 'warning',
          message: '问卷有必填项，请填写必填项!'
        });
      }
    },
    // 取消
    closeDialog() {
      this.$emit('close', false);
    },
    selectChangehf(val) {
      if (val == 10041001) {
        this.formList.find(item => item.fieldName === 'nextVisitDate').disabled = false;
        this.formList.find(item => item.fieldName === 'nextVisitDate').rules = [{ required: true, message: '请选择下次回访时间' }];
      } else {
        this.formList.find(item => item.fieldName === 'nextVisitDate').disabled = true;
        this.formList.find(item => item.fieldName === 'nextVisitDate').initialValue = '';
        this.formList.find(item => item.fieldName === 'nextVisitDate').rules = [];
      }
    },
    // 呼出系统
    exhale(a) {
      let phone = a + this.remindData.phone; // 车主电话
      let userData = {
        userData: {
          // RO_NO: val.RO_NO,
          OWNER_CODE: this.remindData.ownerCode,
          OWNER_NAME: this.remindData.cusName,
          date: moment().format('YYYY-MM-DD hh:MM:SS')
        }
      };
      if (CallCenter.isLogin()) {
        CallCenter.callout(phone, null, null, null, null, userData);
        // this.roNo = val.RO_NO;
      } else {
        this.$notify.warning({ title: '提示信息', message: '没有外呼权限!' });
      }
    },
    after() {
      let that = this;
      CallCenter.addEventListener('after', function(json) {
        console.log('验证是否监听到了after方法=============================>true');
        console.log('返回值================================>begin');
        console.log('返回值录音第一段================================>', json.recordDownloadUrl);
        console.log('返回值录音第二段================================>', json.mediano);
        console.log('返回值录音第三段================================>', json.filename);
        let url = json.recordDownloadUrl + '/' + json.mediano + '?file=' + json.filename;
        console.log('返回值录音路径================================>', url);
        let getCallId = json.callid;
        console.log('返回值CALLID================================>', getCallId);
        that.ctiUrl = url;
        console.log('返回URL值录音后台传递================================>', that.ctiUrl);
        that.callid = getCallId;
        console.log('返回CALLID值录音后台传递================================>', that.callid);
      });
    }
  }
};
</script>
<style lang="less" scoped>
.remindInput {
  width: 100%;
  .left {
    width: 43%;
    float: left;
    .detail_main {
      border: 1px solid #ebeef5;
      margin-bottom: 10px;
      .detail_top {
        background: #f2f2f2;
        border-bottom: 1px solid #ebeef5;
        height: 25px;
        line-height: 25px;
        padding: 0 4px;
        padding-right: 2px;
      }
      .detail_containter {
        padding-top: 10px;
      }
    }
  }
  .right {
    width: 57%;
    float: left;
    box-sizing: border-box;
    padding: 0 4px;
    .detail_main {
      border: 1px solid #ebeef5;
      margin-bottom: 10px;
      .detail_top {
        background: #f2f2f2;
        border-bottom: 1px solid #ebeef5;
        height: 25px;
        line-height: 25px;
        padding: 0 10px;
        padding-right: 10px;
      }
      .detail_containter {
        padding-top: 10px;
      }
    }
  }
}
</style>
